import 'package:flutter/material.dart';
import 'package:flutter/animation.dart';

class MyAnintPage extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("动画"),
      ),
      body: new MyAnint(),
    );
  }


}

class MyAnint extends StatefulWidget{
  @override
  MyAnintState createState() {
    // TODO: implement createState
    return new MyAnintState(
      url: "http://h.hiphotos.baidu.com/image/pic/item/b64543a98226cffc49721710b5014a90f603ea3c.jpg"
    );
  }

}

class MyAnintState extends State<MyAnint> with TickerProviderStateMixin{
  String url="";

  AnimationController controller;

  Animation<double> animation;



  MyAnintState({this.url});


  @override
  void dispose() {
    if(controller!=null)controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Center(
      child: new Column(
        children: <Widget>[
          _loadImagePath(),
          new MaterialButton(onPressed:_playShow(),
          child: new Text("渐变动画"),
          )
        ],
      ),
    );
  }

   _loadImagePath() {
    if(animation!=null){
      return new Container(
          margin: new EdgeInsets.symmetric(vertical: 8.0),
          height: animation.value,
          child: new Image.network(url));
    }else{
      return new Container(
          margin: new EdgeInsets.symmetric(vertical: 8.0),
          height: 500.0,
          child: new Image.network(url));
    }
  }
  _playShow() {
    if(controller!=null){
      controller.dispose();
      controller=null;
    }
     controller=new AnimationController(vsync: this
    ,duration: new Duration( milliseconds: 10000));
    animation =new Tween(begin: 0.0,end: 10000.0).animate(controller)
    ..addListener((){});
     controller.forward();
  }
}
